import { Classes } from '@blueprintjs/core';
import { AddComment16, Chat16, List16, Tag16, User16 } from '@carbon/icons-react';
import type { CarbonIconType } from '@carbon/icons-react';
import type { ComponentProps, FC } from 'react';

export type CarbonIconProps = ComponentProps<'span'> & {
	icon: CarbonIconType | CustomIcon;
	size?: number;
	// SEARCH FOR ICONS HERE: https://www.carbondesignsystem.com/guidelines/icons/library/
};

/** Maps CarbonIcons to Blueprint <Icon/> */
export const CarbonIcon: FC<CarbonIconProps> = ({ icon, size = 16, className, ...props }) => {
	const CarbonIconComponent =
		typeof icon === 'string'
			? () => (
					<svg
						xmlns="http://www.w3.org/2000/svg"
						// xmlns:xlink="http://www.w3.org/1999/xlink"
						width={size}
						height={size}
						viewBox={`0 0 ${size} ${size}`}
					>
						<path d={icon} />
					</svg>
			  )
			: icon; // CarbonIconType

	return (
		<span {...props} className={[Classes.ICON, className].join(' ')}>
			<CarbonIconComponent />
		</span>
	);
};

/** the d="" attribute for an svg <path d={string} /> */
export type SvgPathD = string; // ComponentProps<'path'>['d'];
export type CustomIcon = string; // keyof typeof customIconPaths;

/** custom icon paths for use in <CarbonIcon icon={customIconPaths.icon} /> */
export const customIconPaths = {
	multiComment16:
		'M9,15.5l2-3.5h3c0.6,0,1-0.4,1-1V5c0-0.6-0.4-1-1-1h-2V3h2c1.1,0,2,0.9,2,2v6c0,1.1-0.9,2-2,2c0,0,0,0,0,0h-2.4l-1.7,3 L9,15.5z M4,13c-1.1,0-2-0.9-2-2v-1h1v1c0,0.6,0.4,1,1,1h4.5v1H4z M3,9V7h8v2H3z M0,9V7h2v2H0z M3,6V4h8v2H3z M0,6V4h2v2H0z M3,3V1 h8v2H3z M0,3V1h2v2H0z',
	beacon16:
		'M13.1464 13.8536L9.73826 10.4454C10.0115 10.2508 10.2508 10.0115 10.4454 9.73827L13.8535 13.1464L13.1464 13.8536ZM5.55462 6.26174C5.74922 5.98848 5.98847 5.74922 6.26173 5.55463L2.85355 2.14645L2.14644 2.85355L5.55462 6.26174ZM10 8C10 9.10457 9.10457 10 8 10C6.89543 10 6 9.10457 6 8C6 6.89543 6.89543 6 8 6C9.10457 6 10 6.89543 10 8Z',
	host16:
		'M2 8C2 6.4087 2.63259 4.88254 3.75781 3.75732C4.88303 2.63211 6.4087 2 8 2C9.5913 2 11.117 2.63211 12.2422 3.75732C13.3674 4.88254 14 6.4087 14 8C14 9.5913 13.3674 11.1175 12.2422 12.2427C11.117 13.3679 9.5913 14 8 14C6.4087 14 4.88303 13.3679 3.75781 12.2427C2.63259 11.1175 2 9.5913 2 8ZM3 8C3.00159 9.32559 3.52946 10.5965 4.4668 11.5338C5.40413 12.4712 6.67441 12.9984 8 13C9.32608 13 10.5975 12.4732 11.5352 11.5355C12.4728 10.5978 13 9.32608 13 8C13 6.67392 12.4728 5.40216 11.5352 4.46448C10.5975 3.5268 9.32608 3 8 3C6.67441 3.00159 5.40413 3.52885 4.4668 4.46619C3.52946 5.40352 3.00159 6.67441 3 8ZM7 10.5C7 10.1022 7.15815 9.72064 7.43945 9.43933C7.72076 9.15803 8.10218 9 8.5 9C8.89782 9 9.27924 9.15803 9.56055 9.43933C9.84185 9.72064 10 10.1022 10 10.5C10 10.8978 9.84185 11.2794 9.56055 11.5607C9.27924 11.842 8.89782 12 8.5 12C8.10218 12 7.72076 11.842 7.43945 11.5607C7.15815 11.2794 7 10.8978 7 10.5ZM4 8.5C4 8.10218 4.15815 7.72064 4.43945 7.43933C4.72076 7.15803 5.10218 7 5.5 7C5.89782 7 6.27924 7.15803 6.56055 7.43933C6.84185 7.72064 7 8.10218 7 8.5C7 8.89782 6.84185 9.27936 6.56055 9.56067C6.27924 9.84197 5.89782 10 5.5 10C5.10218 10 4.72076 9.84197 4.43945 9.56067C4.15815 9.27936 4 8.89782 4 8.5ZM9 7.5C9 7.10218 9.15815 6.72064 9.43945 6.43933C9.72076 6.15803 10.1022 6 10.5 6C10.8978 6 11.2792 6.15803 11.5605 6.43933C11.8419 6.72064 12 7.10218 12 7.5C12 7.89782 11.8419 8.27936 11.5605 8.56067C11.2792 8.84197 10.8978 9 10.5 9C10.1022 9 9.72076 8.84197 9.43945 8.56067C9.15815 8.27936 9 7.89782 9 7.5ZM6 5.5C6 5.10218 6.15815 4.72064 6.43945 4.43933C6.72076 4.15803 7.10218 4 7.5 4C7.89782 4 8.27924 4.15803 8.56055 4.43933C8.84185 4.72064 9 5.10218 9 5.5C9 5.89782 8.84185 6.27936 8.56055 6.56067C8.27924 6.84197 7.89782 7 7.5 7C7.10218 7 6.72076 6.84197 6.43945 6.56067C6.15815 6.27936 6 5.89782 6 5.5Z',
	link16:
		'M4 6C5.10457 6 6 5.10457 6 4C6 2.89543 5.10457 2 4 2C2.89543 2 2 2.89543 2 4C2 5.10457 2.89543 6 4 6ZM12 14C13.1046 14 14 13.1046 14 12C14 10.8954 13.1046 10 12 10C10.8954 10 10 10.8954 10 12C10 13.1046 10.8954 14 12 14ZM6.44537 5.73827C6.25078 6.01153 6.01153 6.25078 5.73827 6.44537L9.55462 10.2617C9.74922 9.98847 9.98847 9.74922 10.2617 9.55463L6.44537 5.73827Z',
	linkFrom16:
		'M4 6C5.10457 6 6 5.10457 6 4C6 2.89543 5.10457 2 4 2C2.89543 2 2 2.89543 2 4C2 5.10457 2.89543 6 4 6ZM11.2617 10.5546L8.70711 8H11V7H7V11H8V8.70711L10.5546 11.2617C10.7492 10.9885 10.9885 10.7492 11.2617 10.5546ZM14 13C14 13.5523 13.5523 14 13 14C12.4477 14 12 13.5523 12 13C12 12.4477 12.4477 12 13 12C13.5523 12 14 12.4477 14 13ZM13 15C14.1046 15 15 14.1046 15 13C15 11.8954 14.1046 11 13 11C11.8954 11 11 11.8954 11 13C11 14.1046 11.8954 15 13 15Z',
	linkTo16:
		'M4 6C5.10457 6 6 5.10457 6 4C6 2.89543 5.10457 2 4 2C2.89543 2 2 2.89543 2 4C2 5.10457 2.89543 6 4 6ZM13 14C13.5523 14 14 13.5523 14 13C14 12.4477 13.5523 12 13 12C12.4477 12 12 12.4477 12 13C12 13.5523 12.4477 14 13 14ZM15 13C15 14.1046 14.1046 15 13 15C11.8954 15 11 14.1046 11 13C11 11.8954 11.8954 11 13 11C14.1046 11 15 11.8954 15 13ZM8.2929 9L5.73827 6.44537C6.01153 6.25078 6.25078 6.01152 6.44538 5.73826L9.00001 8.29289V6H10V10H6.00001V9H8.2929Z',
	teamServer16:
		'M12 6.132C12 5.95918 11.9553 5.7893 11.8701 5.63893C11.7849 5.48856 11.6622 5.36283 11.514 5.274L8.514 3.474C8.35858 3.38075 8.18075 3.33149 7.9995 3.33149C7.81825 3.33149 7.64042 3.38075 7.485 3.474L4.485 5.274C4.33694 5.36295 4.21445 5.48874 4.12946 5.6391C4.04446 5.78946 3.99986 5.95928 4 6.132V9.868C3.99996 10.0408 4.04471 10.2107 4.12989 10.3611C4.21507 10.5114 4.33776 10.6372 4.486 10.726L7.486 12.526C7.64142 12.6193 7.81925 12.6685 8.0005 12.6685C8.18175 12.6685 8.35958 12.6193 8.515 12.526L11.515 10.726C11.6631 10.637 11.7855 10.5113 11.8705 10.3609C11.9555 10.2105 12.0001 10.0407 12 9.868V6.132ZM13 6.132V9.868C13 10.2134 12.9106 10.5529 12.7404 10.8534C12.5702 11.1539 12.3252 11.4053 12.029 11.583L9.029 13.383C8.71817 13.5695 8.36249 13.668 8 13.668C7.63751 13.668 7.28183 13.5695 6.971 13.383L3.971 11.583C3.67485 11.4053 3.42976 11.1539 3.25959 10.8534C3.08943 10.5529 3 10.2134 3 9.868V6.132C3 5.78663 3.08943 5.44714 3.25959 5.1466C3.42976 4.84605 3.67485 4.5947 3.971 4.417L6.971 2.617C7.28183 2.4305 7.63751 2.33198 8 2.33198C8.36249 2.33198 8.71817 2.4305 9.029 2.617L12.029 4.417C12.3252 4.5947 12.5702 4.84605 12.7404 5.1466C12.9106 5.44714 13 5.78663 13 6.132V6.132Z',
};

/** Mapping for icons that are used in several locations */
export const semanticIcons = {
	commands: List16,
	comment: Chat16,
	addComment: AddComment16,
	operator: User16,
	beacon: customIconPaths.beacon16,
	host: customIconPaths.host16,
	link: customIconPaths.link16,
	linkTo: customIconPaths.linkTo16,
	linkFrom: customIconPaths.linkFrom16,
	teamServer: customIconPaths.teamServer16,
	tags: Tag16,
};
